﻿using System.Runtime.InteropServices;

namespace AutoRevit.Utils
{
    internal class RevitInputUtils
    {
        /// <summary>
        /// 执行次数
        /// </summary>
        /// <param name="count"></param>
        internal static void ActionEsc(int count)
        {
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    ActionEsc();
                }
            }
        }

        /// <summary>
        /// 执行按下Esc按钮
        /// </summary>
        internal static void ActionEsc()
        {
            IntPtr revit = Autodesk.Windows.ComponentManager.ApplicationWindow;
            SetForegroundWindow(revit);
            keybd_event(27, 0, 0, 0);
            keybd_event(27, 0, 2, 0);
        }

        [DllImport("user32.dll")]
        private static extern bool SetForegroundWindow(IntPtr hWnd);

        [DllImport("user32.dll")]
        private static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
    }
}
